package com.wwjd.starter.canal.config;

import com.wwjd.starter.canal.client.core.SimpleCanalClient;
import com.wwjd.starter.canal.client.interfaces.CanalClient;
import com.wwjd.starter.canal.util.ApplicationContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

/**
 * @author Administrator
 */
@Slf4j
public class CanalClientConfiguration {
    /**
     * canal 配置
     */
    @Autowired
    private CanalProperties canalProperties;

    /**
     * 返回 bean 工具类
     *
     * @param
     * @return
     * @author 阿导
     * @time 2018/5/28 14:14
     * @CopyRight 万物皆导
     */
    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    public ApplicationContextUtils applicationContextUtils() {
        return new ApplicationContextUtils();
    }

    /**
     * 返回 canal 的客户端
     *
     * @param
     * @return
     * @author 阿导
     * @time 2018/5/28 14:15
     * @CopyRight 万物皆导
     */
    @Bean
    private CanalClient canalClient() {
        CanalClient canalClient = new SimpleCanalClient(canalProperties);
        canalClient.start();
        log.info("连接 canal 客户端成功...");
        return canalClient;
    }
}
